﻿package mortal.game.view.platform
{
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class PlatformVerificController extends Controller
    {
        private var _module:PlatformVerificModule;

        public function PlatformVerificController()
        {
            PlatformVerificModule.platformData = PlatformVerificUtil.getPanelData();
            return;
        }// end function

        protected function checkIsShowIcon(param1:Object = null) : void
        {
            if (ParamsConst.instance.platformMobileVerificUrl && !ClientSetting.local.getIsDone(IsDoneType.IsGetPlatformVerificReward))
            {
                PlatformVerificIcon.instance.showIconByBtnName(PlatformVerificUtil.getIconResName());
            }
            else
            {
                if (PlatformVerificIcon.isViewShow())
                {
                    PlatformVerificIcon.instance.hide();
                }
                if (isViewShow)
                {
                    view.hide();
                }
            }
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._module == null)
            {
                this._module = new PlatformVerificModule();
                this._module.addEventListener(WindowEvent.SHOW, this.onShow);
                this._module.addEventListener(WindowEvent.CLOSE, this.onClose);
            }
            return this._module;
        }// end function

        protected function onShow(event:WindowEvent) : void
        {
            return;
        }// end function

        protected function onClose(event:WindowEvent) : void
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.PlatformVerificShow, this.onPlatformViewShow);
            Dispatcher.addEventListener(EventName.PlatformRequestVerificGift, this.onRequestGift);
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.onLoginSuccess);
            NetDispatcher.addCmdListener(ServerCommand.SystemClientSettingGot, this.checkIsShowIcon);
            NetDispatcher.addCmdListener(ServerCommand.ActivationTakeBackInfo, this.panduanLiBao);
            return;
        }// end function

        private function onLoginSuccess(param1:Object) : void
        {
            this.checkIsShowIcon();
            return;
        }// end function

        private function panduanLiBao(param1:int) : void
        {
            if (param1 == 41 || param1 == 52 || param1 == 53)
            {
                this.onVerificSuccess();
            }
            else if (param1 < 0)
            {
                MsgManager.showRollTipsMsg("激活码输入错误");
            }
            return;
        }// end function

        private function onVerificSuccess(event:Event = null) : void
        {
            MsgManager.showRollTipsMsg("领取成功");
            ClientSetting.local.setIsDone(true, IsDoneType.IsGetPlatformVerificReward);
            ClientSetting.save();
            this.checkIsShowIcon();
            return;
        }// end function

        private function onRequestGift(event:DataEvent) : void
        {
            GameProxy.Platform.getPlatformGift(int(event.data));
            return;
        }// end function

        private function onPlatformViewShow(event:Event) : void
        {
            if (!isViewShow)
            {
                view.show();
            }
            else
            {
                view.hide();
            }
            return;
        }// end function

    }
}
